package com.zmn.mcc.cas.staff.log.task;

import com.alibaba.fastjson.JSON;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.mcc.cas.CasConstants;
import com.zmn.mcc.cas.model.StaffLog;
import com.zmn.mcc.cas.staff.log.service.interfaces.StaffLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 员工操作日志监听
 *
 * @author quanjic
 * @version v1.0
 * @since 2019/7/8 18:03
 **/
@AliyunMQListener(topic = "${zmn.admin.staff.log.topic}")
@Component
public class StaffLogListener {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private StaffLogService staffLogService;


    @AliyunMQHandler(tags = CasConstants.STAFF_LOG_TOPIC_TAG)
    public void handle(String message) {
        try {
            StaffLog staffLog = JSON.parseObject(message, StaffLog.class);
            staffLogService.save(staffLog);
        } catch (Exception e) {
            logger.error("#staff_log# 保存操作日志失败", e);
            throw e;
        }

    }

}
